import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @program: data_structures_algorithms
 * @description:
 * @author: lld
 * @create: 2021-04-22 19:39
 **/
class AllSort2 {
    public static void main(String[] args) {
        AllSort2 allSort2 = new AllSort2();
        int[] nums={1,2,3};
        List<List<Integer>> permute = allSort2.permute(nums);
        System.out.println(permute);
    }
    public List<List<Integer>> permute(int[] nums) {
        List<List<Integer>> list = new ArrayList<>();
        List<Integer> list1 = new ArrayList<>();
        dfs(nums, list, list1);
        return list;
    }

    public void dfs(int[] nums, List<List<Integer>> list, List<Integer> list1) {
        if (list1.size() == nums.length) {
            list.add(new ArrayList<>(list1));
            return;
        }
        for (int i = 0; i < nums.length; i++) {
            if (list1.contains(nums[i])) continue;
            list1.add(nums[i]);
            dfs(nums, list, list1);
            list1.remove(list1.size() - 1);
        }
    }
}

